﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LibraryO2S;
public partial class Administrator_ModuleAdd : System.Web.UI.Page
{

    private BusinessController objBus = new BusinessController();
    BizNews news = new BizNews();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadToCombobox();
        }
    }

    public void LoadToCombobox()
    {
        BizModule module = new BizModule();
        ddlModule.DataSource = module.SelectAll();
        ddlModule.DataTextField = "DESCRIPTION";
        ddlModule.DataValueField = "MODULEID";
        ddlModule.DataBind();
    }
    public int GetRandom()
    {
        Random rd = new Random();
        int a = rd.Next(1, 100);
        return a;
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        int status = 0;
        if (cbStatus.Checked)
        {
            status = 1;
        }
        else
            status = 0;
        try
        {
            string createdby = Session["USERNAME"].ToString();
            string filname = "";
            if (fuImage.HasFile)
            {
                filname = GetRandom() + "" + fuImage.FileName;
                fuImage.SaveAs(Server.MapPath("~/ImageNews/") + filname);
            }
            news.Insert(txtTitle.Text, filname, txtSumary.Text, int.Parse(ddlModule.SelectedValue), int.Parse(txtSortDisplay.Text), txtContent.Text, txtSEODescription.Text, txtSEOKeyWord.Text, createdby, status);
            //objBus.ResizeImage(filname, "ImageNews", "imgnews", 557, 285);
            //objBus.ResizeImage(filname, "ImageNews", "imgnewscrop", 183, 122);
            divMessage.InnerHtml = O2S_Message.Success("Hệ thống", "Thực hiện thành công");
            txtTitle.Text = "";
            txtSumary.Text = "";
            txtContent.Text = "";
            cbStatus.Checked = false;


        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Hệ thống", "Phát hiện lỗi" + ex.Message);
        }

    }
}